# Contributor: Francesco Camuffo <dev@fmac.xyz>
# Maintainer: Francesco Camuffo <dev@fmac.xyz>
pkgname=faust
pkgver=2.40.0
pkgrel=1
pkgdesc="Functional programming language for realtime audio signal processing"
url="https://faust.grame.fr"
arch="all"
license="GPL-2.0-or-later"
checkdepends="bash"
makedepends="
	cmake
	libexecinfo-dev
	libmicrohttpd-dev
	libsndfile-dev
	llvm-dev
	samurai
	"
subpackages="
	$pkgname-tools
	$pkgname-static
	$pkgname-doc
	$pkgname-dev
	$pkgname-vim::noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/grame-cncm/faust/releases/download/$pkgver/faust-$pkgver.tar.gz
	faust-musl-stacktrace.patch
	llvm14.patch
	"

build() {
	cmake -B "$pkgname"-build \
		-G Ninja \
		-S build \
		-C build/backends/all.cmake \
		-C build/targets/all.cmake \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DINCLUDE_DYNAMIC=ON \
		-DINCLUDE_STATIC=ON \
		-DINCLUDE_ITP=ON \
		-Wno-dev
	VERBOSE=1 cmake --build "$pkgname"-build
	make VERBOSE=1 -C tools/sound2faust
}

check() {
	make interp -C tests/compile-tests
}

package() {
	DESTDIR="$pkgdir" cmake --install "$pkgname"-build
	make VERBOSE=1 PREFIX=/usr DESTDIR="$pkgdir" install -C tools/sound2faust

	# remove support for platforms not likely wanted
	rm -rvf "$pkgdir"/usr/bin/faust2au \
		"$pkgdir"/usr/lib/ios-libsndfile.a \
		"$pkgdir"/usr/share/faust/AU \
		"$pkgdir"/usr/share/faust/android \
		"$pkgdir"/usr/share/faust/iOS \
		"$pkgdir"/usr/share/faust/smartKeyboard \
		"$pkgdir"/usr/share/faust/max-msp/sndfile
	# rename generically named usage script
	mv "$pkgdir"/usr/bin/usage.sh "$pkgdir"/usr/bin/faust-usage.sh
}

dev() {
	pkgdesc="$pkgdesc (development files)"
	amove usr/include/* \
		usr/lib/*.so
}

tools() {
	pkgdesc="$pkgdesc (tools)"
	amove usr/bin/encoderunitypackage \
		usr/bin/faust2* \
		usr/bin/filename2ident \
		usr/bin/sound2*
}

vim() {
	pkgdesc="$pkgdesc (vim syntax)"
	install_if="vim $pkgname=$pkgver-r$pkgrel"

	cd "$builddir"/syntax-highlighting
	install -Dm644 faust.vim -t "$subpkgdir"/usr/share/vim/vimfiles/syntax/
}

sha512sums="
7ecb334b95042caa3a44ecbb711a972b6f979afca4c67fc4f32acf548ed85472e941c6590a139464aeb5266c3e88fe639e2060a110a98e88fd7b1994e0a87650  faust-2.40.0.tar.gz
f3e07bdd26ab8f0ffbf0c0dfbf8141facc07d2db05346f3b982faca613aa5ecad8986683db8d49caed720d58b183b215d6e1c4ceef069f29f41bcfa699ad5f28  faust-musl-stacktrace.patch
e28a76fe56deeac83c2f751933e6106c4f4e9903c7b8ec850eeb98f482cf85b37973caba96525f583b59952d0017c50f5956d537ac3f40fb88774bdc74ae2cec  llvm14.patch
"
